package com.loobot.album.controller;

import com.loobot.album.config.secure.gateway.LoobotAccount;
import com.loobot.album.config.secure.gateway.PartnerThreadLocal;
import com.loobot.album.dao.model.Album;
import com.loobot.album.net.RestResult;
import com.loobot.album.net.RestResultGenerator;
import com.loobot.album.net.param.request.AddAlbum;
import com.loobot.album.net.param.request.GetAlbum;
import com.loobot.album.net.param.request.GetPictures;
import com.loobot.album.service.AlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Ike.Fan
 * @date: 2019/3/14.
 */
@Api("相册api")
@RequestMapping("album")
@RestController
public class AlbumController {
    @Autowired
    AlbumService albumService;

    @ApiOperation(value = "获取相册")
    @GetMapping("/get/{ownerId}")
    public RestResult<Album> getAlbum(@PathVariable String ownerId){
        return RestResultGenerator.genSuccessResult(albumService.getAlbumByOwnerId(ownerId));
    }

    @ApiOperation(value = "获取相册列表")
    @PostMapping("/list/")
    public RestResult<List<Album>> listAlbums(@RequestBody GetAlbum getAlbum){
        return RestResultGenerator.genSuccessResult(albumService.getAlbums(getAlbum));
    }

    @ApiOperation(value = "添加相册")
    @PostMapping("/add")
    public RestResult<String>addAlbum(@Validated @RequestBody AddAlbum addAlbum){
        LoobotAccount header = PartnerThreadLocal.get();
        Album album = new Album();
        album.setName(addAlbum.getName());
        album.setOwnerId(addAlbum.getOwnerId());
        album.setProjectId(header.getAppId()+"");
        String rt = albumService.addAlbum(album);
        System.out.println("add rt="+rt);
        return RestResultGenerator.genSuccessResult(rt);
    }
    @ApiOperation(value = "删除相册")
    @PostMapping("/delete/{uuid}")
    public RestResult<Integer>delete(@PathVariable(value = "uuid")  String uuid){
        return RestResultGenerator.genSuccessResult(albumService.delete(uuid));
    }

}
